package com.foruo.algo.polling;

/**
 * 轮询算法
 * @author GaoYuan
 * @date 2018/10/24 下午2:58
 */
public class PollingAlgo {

    /** 从下标 0 开始读取 */
    private static volatile int index = 0;
    /** 假设目前集群有4个服务 */
    private static String[] urls = {"url1","url2","url3","url4"};

    public static String getTarget(){
        if(index >= urls.length){
            index = 0;
        }
        return urls[index++];
    }


    public static void main(String[] args){
        for(int i=0;i<12;i++){
            System.out.println(getTarget());
        }
    }
}
